// echart公共option
function PublicOption(title) {
    this.title = {
        show: true,
        text: title,
        left: 'center',
        textStyle: {
            fontSize: 16,
            color: '#01d2ff'
        },
        top: 5,
    };
    this.toolbox = {
        show: true,
        right: '20px',
        top: '10px',
        feature: {
            dataView: {
                show: false
            },
            saveAsImage: {
                show: true,
                name: title,
                excludeComponents: ['toolbox'],
                pixelRatio: 2,
            }
        }
    };
    this.dataZoom = {
        show: true,
        height: 20,
        bottom: 15,
        start: 0,
        end: 100,
        handlecolor: '#ddd',
        handlestyle: {
            borderColor: '#cacaca',
            borderWidth: "1",
            shadowBlur: 2,
            background: "#ddd",
            shadowcolor: "#ddd",
        },
        type: 'slider',
    };
}

// 1柱状图 3折线图 曲线图 下钻
function showBarOrLine(chartData, chart, type, area, smooth) {
    // chartData = {
    //     "responseData": {
    //         "dimension": [
    //             [
    //                 '周一',
    //                 '周二',
    //                 '周三',
    //                 '周四',
    //                 '周五',
    //                 '周六',
    //                 '周日',
    //             ],
    //             ["语文", "数学", "英语", "物理", "化学"]
    //         ],
    //         "measure": [
    //             [1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 34, 37, 40, 43, 46, 49, 52, 55, 58, 61, 64, 67, 70, 73, 76, 79, 82, 85, 88, 91, 94, 97, 100, 103],
    //             // [2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 32, 35, 38, 41, 44, 47, 50, 53, 56, 59, 62, 65, 68, 71, 74, 77, 80, 83, 86, 89, 92, 95, 98, 101, 104],
    //             // [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60, 63, 66, 69, 72, 75, 78, 81, 84, 87, 90, 93, 96, 99, 102, 105]
    //         ],
    //         "dimensionName": ["星期", "课程"],
    //         "measureName": ["小时" /* , "分钟", "秒" */ ]
    //     }
    // };

    var responseData = chartData.responseData;
    // type = 'line';
    type = type || 'line';
    var typeName = type == 'line' ? '折线图' : '柱状图';

    // 1-1/n 2-1
    if (responseData.dimensionName.length != 1 && (responseData.dimensionName.length != 2 || responseData.measureName.length != 1)) {
        console.log('此数据无法使用' + typeName + '表示');
        return false;
    }

    var legendData;
    var xAxisData = responseData.dimension[0];
    var yAxisData = {
        type: 'value'
    };

    var series;
    if (responseData.dimensionName.length == 1) {
        legendData = responseData.measureName;
        if (responseData.measureName.length == 1) {
            yAxisData.name = responseData.measureName[0];
            series = {
                data: responseData.measure[0],
                type: type,
                name: responseData.measureName[0],
            };
            if (area) {
                series.areaStyle = {};
                series.stack = true;
            }
            if (smooth) {
                series.smooth = true;
            }
        } else {
            series = responseData.measureName.map(function(item, index) {
                var result = {
                    name: item,
                    type: type,
                    data: responseData.measure[index],
                };
                if (area) {
                    result.areaStyle = {};
                    result.stack = true;
                }
                if (smooth) {
                    result.smooth = true;
                }
                return result;
            });
        }
    } else if (responseData.dimensionName.length == 2) {
        yAxisData.name = responseData.measureName[0];
        series = responseData.dimension[1].map(function(item, index) {
            var result = {
                type: type,
                data: [],
            };
            if (area) {
                result.areaStyle = {};
                result.stack = true;
            }
            if (smooth) {
                result.smooth = true;
            }
            responseData.dimension[0].map(function(item2, index2) {
                result.name = item;
                var measureIndex = index2 * responseData.dimension[1].length + index;
                result.data.push(responseData.measure[0][measureIndex]);
            });
            return result;
        });
    }

    var option = {
        tooltip: {
            confine: true,
            trigger: 'axis',
        },
        grid: {
            left: '15px',
            right: 70,
            top: 60,
            bottom: '40px',
            containLabel: true
        },
        legend: {
            data: legendData,
            top: '30',
            padding: [
                0, // 上
                100, // 右
                0, // 下
                100, // 左
            ],
            type: 'scroll',
        },
        xAxis: {
            type: 'category',
            data: xAxisData,
            name: responseData.dimensionName[0],
            nameLocation: 'end'
        },
        yAxis: yAxisData,
        series: series
    };

    Object.assign(option, new PublicOption(chart.title));
    chart.setOption(option);

    window.addEventListener("resize", function() {
        chart.resize();
    });


    return;
    var clickValue;
    var newxdata = [];
    var newydata = [];
    if (showway == "1对n") {
        for (var i = 0; i < yvalue.length; i++) {
            var obj = new Object();
            // obj.name = vm.measureSelected[i].FIELDNAME;
            obj.name = that.measureSelected[i].FIELDNAME;
            obj.type = '' + way;
            obj.data = yvalue[i];
            newydata.push(obj);
        }
        for (var i = 0; i < xdata[0].length; i++) {
            newxdata.push(xdata[0][i]);
        }
    } else if (showway == "1对1") {
        var obj = new Object();
        obj.name = vm.measureSelected[0].FIELDNAME;
        obj.type = '' + way;
        obj.barWidth = '80%';
        obj.data = yvalue;
        newydata.push(obj);
        for (var i = 0; i < xdata.length; i++) {
            newxdata.push(xdata[i]);
        }
    } else if (showway == "2对1") {
        for (var i = 0; i < xdata[0].length; i++) {
            if (newxdata.length == 0)
                newxdata.push(xdata[0][i]);
            if (xdata[0][i] != newxdata[newxdata.length - 1])
                newxdata.push(xdata[0][i]); //newxdata放横坐标
        }
        var aNewArr = []; //定义一个临时数组
        for (var i = 0; i < xdata[1].length; i++) { //循环遍历当前数组
            //判断当前数组下标为i的元素是否已经保存到临时数组
            //如果已保存，则跳过，否则将此元素保存到临时数组中
            if (aNewArr.indexOf(xdata[1][i]) == -1) {
                aNewArr.push(xdata[1][i]);
            }
        }
        var aNewArr2 = [];
        for (var i = 0; i < aNewArr.length; i++) {
            // var arr = [];
            var arr = new Array(newxdata.length);
            aNewArr2.push(arr);
        }

        // aNewArr 城镇村属性码
        // newxdata 地类名称
        // 遍历每一条数据(例如:城镇村属性码)
        for (var i = 0; i < xdata[1].length; i++) {
            // 当前已选维度
            // 城镇村属性码
            var m = aNewArr.indexOf(xdata[1][i]);
            // 地类名称
            var n = newxdata.indexOf(xdata[0][i]);
            aNewArr2[m][n] = yvalue[0][i];
        }

        for (var i = 0; i < aNewArr2.length; i++) {
            var obj = new Object();
            obj.name = aNewArr[i];
            obj.type = "" + way;
            obj.data = aNewArr2[i];
            newydata.push(obj);
        }
    }

    chart.setOption({ //加载数据图表
        title: Object.assign({ text: chart.title }, titleOption),
        // color: globalColor,
        tooltip: {
            confine: true,
            show: true,
            trigger: 'axis',
            axisPointer: {
                type: 'shadow'
            }
        },
        grid: {
            left: '15px',
            right: '20px',
            bottom: '40px',
            top: '40px',
            containLabel: true
        },
        toolbox: {
            show: true,
            right: '20px',
            top: '10px',
            feature: {
                dataView: {
                    show: false
                },
                saveAsImage: {
                    show: true,
                    name: '图',
                    excludeComponents: ['toolbox'],
                    pixelRatio: 2,
                }
            },
        },
        xAxis: {
            type: 'category',
            boundaryGap: true,
            data: newxdata,
            axisLabel: {
                textStyle: {
                    fontSize: 10
                }
            },
        },
        yAxis: {
            type: 'value',
            name: '单位(公顷)',
            axisLabel: {
                formatter: '{value}', //给y轴添加单位
                textStyle: {
                    fontSize: 10
                }
            }
        },
        series: newydata,

        formatter: function(val) {
            clickValue = val[0];
            var html = '';
            val.forEach(function(item, index) {
                var name = item.name;
                var color = item.color;
                var seriesName = item.seriesName;
                var value = item.value || '';
                if (index == 0) {
                    html += name;
                }
                html += `<br><span style="display:inline-block;margin-right:5px;border-radius:10px;width:9px;height:9px;background-color:` + color + `;"></span>` + seriesName + `: ` + value;
            });
            return html;
        }
    });
    window.addEventListener("resize", function() {
        chart.resize();
    });

    chart.asFilter = false;
    chart.off('click');
    chart.getZr().on('mousedown', function(params) {
        if (!$(chart._dom).hasClass('echartContent')) {
            return;
        }
        console.log(clickValue);
        const pointInPixel = [params.offsetX, params.offsetY];
        if (chart.containPixel('grid', pointInPixel)) {
            var xIndex = chart.convertFromPixel({
                seriesIndex: 0
            }, [params.offsetX, params.offsetY])[0];
            vm.stopPropagation = true;

            if (params.event.which == 3) {
                var res;
                if (chart.asFilter) {
                    res = confirm('取消筛选器');
                    if (res) {
                        chart.asFilter = false;
                    }
                } else {
                    res = confirm('用作筛选器');
                    if (res) {
                        chart.asFilter = true;
                    }
                }
            } else {
                if (chart.asFilter) {
                    vm.toast('已将“' + clickValue.name + '”设为筛选器');
                    var index = $(chart._dom).parent().index();
                    var data = vm.totalData[index];
                    if (data) {
                        vm.setGlobalFilterData(data.dimensionSelected[0].FIELDNAME, clickValue.name, {
                            dataBaseSelected: data.dataBaseSelected,
                            tableTypeSelected: data.tableTypeSelected,
                            tableDataSelected: data.tableDataSelected
                        }, index);
                    }
                }
            }
        }
    });
}

// 2饼图 7环状图 下钻
// function showPieOrRing (xdata, yvalue, chart, way) {
function showPieOrRing(chartData, chart, radius) {
    var responseData = chartData.responseData;

    // radius = ['50%', '60%'];
    radius = radius || '60%';
    var typeName = typeof(radius) == 'string' ? '饼状图' : '环状图';

    // 1-1
    if (responseData.dimensionName.length != 1 || responseData.measureName.length != 1) {
        console.log('此数据无法使用' + typeName + '表示');
        return false;
    }

    var legendData = responseData.dimension[0];
    var seriesData = responseData.measure[0].map(function(item, index) {
        return {
            value: item,
            name: responseData.dimension[0][index]
        };
    });

    var option = {
        tooltip: {
            confine: true,
            trigger: 'item',
            formatter: '{a} <br/>{b} : {c} ({d}%)'
        },
        legend: {
            top: 50,
            bottom: 20,
            left: 20,
            // top: 'middle',
            orient: 'vertical',
            data: legendData,
            type: 'scroll'
        },
        series: [{
            name: responseData.measureName[0],
            type: 'pie',
            center: ['60%', '55%'],
            data: seriesData,
            emphasis: {
                itemStyle: {
                    shadowBlur: 10,
                    shadowOffsetX: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
            },
            top: 0,
            bottom: 0,
            radius: radius
        }]
    };

    Object.assign(option, new PublicOption(chart.title));
    option.dataZoom = null;
    chart.setOption(option);

    window.addEventListener("resize", function() {
        chart.resize();
    });



    return
    var newData = [];
    for (var i = 0; i < xdata.length; i++) {
        var obj = new Object();
        obj.name = xdata[i];
        obj.value = yvalue[i];
        newData.push(obj);
    }
    chart.setOption({
        title: {
            show: true,
            text: chart.title,
            left: 'center'
        },
        // color: globalColor,
        tooltip: {
            confine: true,
            show: true
        },
        // backgroundColor: '#2d3041',
        // backgroundColor: '',
        legend: {
            type: 'scroll',
            // orient 设置布局方式，默认水平布局，可选值：'horizontal'（水平） ¦ 'vertical'（垂直）
            orient: 'vertical',
            // x 设置水平安放位置，默认全图居中，可选值：'center' ¦ 'left' ¦ 'right' ¦ {number}（x坐标，单位px）
            x: 'left',
            // y 设置垂直安放位置，默认全图顶端，可选值：'top' ¦ 'bottom' ¦ 'center' ¦ {number}（y坐标，单位px）
            y: 'center',
            itemWidth: 18, // 设置图例图形的宽
            itemHeight: 12, // 设置图例图形的高
            textStyle: {
                // color: 'white', // 图例文字颜色
                fontSize: 12
            },
            // itemGap设置各个item之间的间隔，单位px，默认为10，横向布局时为水平间隔，纵向布局时为纵向间隔
            itemGap: 4,
            data: xdata
        },
        series: {
            // 根据名字对应到相应的系列
            name: '总面积',
            label: { //饼图图形上的文本标签
                normal: {
                    show: true,
                    //position:'inner', //标签的位置
                    textStyle: {
                        fontSize: 10 //文字的字体大小
                    },
                    formatter: '{b}:{d}%'
                }
            },
            data: newData,
            type: 'pie',
            radius: way,
            center: ['50%', '50%'],
        },
    });

    window.addEventListener("resize", function() {
        chart.resize();
    });
    // nowChart.push(chart);

    var clickValue;
    chart.asFilter = false;
    chart.off('click');
    // 点击扇区
    chart.on('mousedown', function(params) {
        if (!$(chart._dom).hasClass('echartContent')) {
            return;
        }
        vm.stopPropagation = true;
        clickValue = params;

        if (params.event.event.which == 3) {
            var res;
            if (chart.asFilter) {
                res = confirm('取消筛选器');
                if (res) {
                    chart.asFilter = false;
                }
            } else {
                res = confirm('用作筛选器');
                if (res) {
                    chart.asFilter = true;
                }
            }
        } else {
            if (chart.asFilter) {
                vm.toast('已将“' + clickValue.name + '”设为筛选器');
                var index = $(chart._dom).parent().index();
                var data = vm.totalData[index];
                if (data) {
                    vm.setGlobalFilterData(data.dimensionSelected[0].FIELDNAME, clickValue.name, {
                        dataBaseSelected: data.dataBaseSelected,
                        tableTypeSelected: data.tableTypeSelected,
                        tableDataSelected: data.tableDataSelected
                    }, index);
                }
            }
        }
    });
    chart.on('legendselectchanged', function() {
        vm.stopPropagation = true;
    });
    chart.on('legendscroll', function() {
        vm.stopPropagation = true;
    });
}

// 4树图(方块图) 下钻
function showTreeMap(chartData, chart) {
    var responseData = chartData.responseData;

    // 1-1
    if (responseData.dimensionName.length != 1 || responseData.measureName.length != 1) {
        console.log('此数据无法使用矩形树图表示');
        return false;
    }

    var legendData = responseData.dimension[0];
    var seriesData = responseData.measure[0].map(function(item, index) {
        return {
            value: item,
            name: responseData.dimension[0][index]
        };
    });

    var option = {
        series: [{
            top: 40,
            bottom: 20,
            type: 'treemap',
            data: seriesData,
            roam: false,
            breadcrumb: {
                show: false
            }
        }],
        tooltip: {
            confine: true,
            formatter: '{b0}: {c0}'
        }
    };

    Object.assign(option, new PublicOption(chart.title));
    option.dataZoom = null;
    chart.setOption(option);

    window.addEventListener("resize", function() {
        chart.resize();
    });

    return;
    var newdata = [];
    for (var i = 0; i < xdata.length; i++) {
        var obj = new Object();
        obj.name = xdata[i];
        obj.value = parseFloat(yvalue[i]);
        newdata.push(obj);
    }

    chart.setOption({
        title: {
            show: true,
            text: chart.title,
            left: 'center'
        },
        // color: globalColor,
        // tooltip: {
        //     show: true,
        //     trigger: 'axis',
        //     axisPointer: {
        //         type: 'shadow'
        //     }
        // },
        tooltip: {
            confine: true,
            formatter: function(info) {
                var name = info.name;
                var value = info.value;
                return '<div class="tooltip-title">' + name + ':' + value + '</div>';
            }
        },

        // backgroundColor: '#2d3041',
        // backgroundColor: '',
        series: {
            data: newdata,
            type: 'treemap',
            label: { //饼图图形上的文本标签
                normal: {
                    show: true,
                    //position:'inner', //标签的位置
                    textStyle: {
                        fontSize: 10, //文字的字体大小
                        color: chart._theme.textStyle ? chart._theme.textStyle.color : 'white'
                    },
                    formatter: '{b0}: {c0}'
                }
            }
        },
        toolbox: {
            show: true,
            right: '20px',
            top: '10px',
            feature: {
                dataView: {
                    show: false
                },
                saveAsImage: {
                    show: true,
                    name: '图',
                    excludeComponents: ['toolbox'],
                    pixelRatio: 2,
                    // backgroundColor: '#2d3041'
                }
            },
            iconStyle: {
                normal: {
                    // color: 'white', //设置颜色
                }
            }
        },
    });

    window.addEventListener("resize", function() {
        chart.resize();
    });
    // nowChart.push(chart);

    var clickValue;
    chart.asFilter = false;
    chart.off('click');
    // 点击
    chart.on('mousedown', function(params) {
        if (!$(chart._dom).hasClass('echartContent')) {
            return;
        }
        vm.stopPropagation = true;
        clickValue = params;

        if (params.event.event.which == 3) {
            var res;
            if (chart.asFilter) {
                res = confirm('取消筛选器');
                if (res) {
                    chart.asFilter = false;
                }
            } else {
                res = confirm('用作筛选器');
                if (res) {
                    chart.asFilter = true;
                }
            }
        } else {
            if (chart.asFilter) {
                vm.toast('已将“' + clickValue.name + '”设为筛选器');
                var index = $(chart._dom).parent().index();
                var data = vm.totalData[index];
                if (data) {
                    vm.setGlobalFilterData(data.dimensionSelected[0].FIELDNAME, clickValue.name, {
                        dataBaseSelected: data.dataBaseSelected,
                        tableTypeSelected: data.tableTypeSelected,
                        tableDataSelected: data.tableDataSelected
                    }, index);
                }
            }
        }
        // 虽然报错,但是必不可少
        // chart.click();
    });
    chart.on('legendselectchanged', function() {
        vm.stopPropagation = true;
    });
}

// 5 面积图(调用折线图)
function showAreaLine(chartData, chart) {
    showBarOrLine(chartData, chart, 'line', true);



    return;
    chart.setOption({ //加载数据图表
        title: {
            show: true,
            text: chart.title,
            left: 'center'
        },
        // color: globalColor,
        tooltip: {
            confine: true,
            show: true,
            trigger: 'axis',
            axisPointer: {
                type: 'shadow'
            }
        },
        // backgroundColor: '#2d3041',
        // backgroundColor: '',
        legend: {
            data: newxdata,
            textStyle: {
                // color: 'white',
            }
        },
        grid: {
            left: '15px',
            right: '20px',
            bottom: '40px',
            top: '40px',
            containLabel: true
        },
        toolbox: {
            show: true,
            right: '20px',
            top: '10px',
            feature: {
                dataView: {
                    show: false
                },
                saveAsImage: {
                    show: true,
                    name: '图',
                    excludeComponents: ['toolbox'],
                    pixelRatio: 2,
                    // backgroundColor: '#2d3041'
                }
            },
            iconStyle: {
                normal: {
                    // color: 'white', //设置颜色
                }
            }
        },
        xAxis: {
            type: 'category',
            boundaryGap: true,
            data: newxdata,
            axisLabel: {
                // formatter:'{value}(平方米)',  //给x轴添加单位
                textStyle: {
                    // color: 'white',
                    fontSize: 10
                }
            },
            axisLine: {
                lineStyle: {
                    // color: 'white'
                }
            },
            splitLine: {
                lineStyle: {
                    // color: 'rgba(170,170,170,1)'
                }
            }
        },
        yAxis: {
            type: 'value',
            name: '单位(公顷)',
            axisLabel: {
                formatter: '{value}', //给y轴添加单位
                textStyle: {
                    // color: 'white',
                    fontSize: 10
                }
            },
            axisLine: {
                lineStyle: {
                    // color: 'white'
                }
            },
        },
        dataZoom: {
            show: true,
            height: 20,
            bottom: 16,
            start: 0,
            end: 50,
            handlecolor: '#ddd',
            handlestyle: {
                borderColor: '#cacaca',
                borderWidth: "1",
                shadowBlur: 2,
                background: "#ddd",
                shadowcolor: "#ddd",
            },
            // filercolor: (1, 0, 0, 0,[{
            //     offset: 0,
            //     color: '#1eb5e5'
            // }, {
            //     offset: 1,
            //     color: '#5ccbb1'
            // }]),
            // backgroundColor: '#295d8e',
            type: 'slider',
        },
        series: newydata,

        formatter: function(val) {
            clickValue = val[0];
            var html = '';
            val.forEach(function(item, index) {
                var name = item.name;
                var color = item.color;
                var seriesName = item.seriesName;
                var value = item.value || '';
                if (index == 0) {
                    html += name;
                }
                html += `<br><span style="display:inline-block;margin-right:5px;border-radius:10px;width:9px;height:9px;background-color:` + color + `;"></span>` + seriesName + `: ` + value;
            });
            return html;
        }
    });

    // pictureChart.dispatchAction({
    //     type: 'takeGlobalCursor',
    //     key: 'dataZoomSelect',
    //     // 启动或关闭
    //     dataZoomSelectActive: true
    // });

    window.addEventListener("resize", function() {
        chart.resize();
    });
    // nowChart.push(chart)

    chart.asFilter = false;
    chart.off('click');
    chart.getZr().on('mousedown', function(params) {
        if (!$(chart._dom).hasClass('echartContent')) {
            return;
        }
        console.log(clickValue);
        const pointInPixel = [params.offsetX, params.offsetY];
        if (chart.containPixel('grid', pointInPixel)) {
            var xIndex = chart.convertFromPixel({
                seriesIndex: 0
            }, [params.offsetX, params.offsetY])[0];
            vm.stopPropagation = true;

            if (params.event.which == 3) {
                var res;
                if (chart.asFilter) {
                    res = confirm('取消筛选器');
                    if (res) {
                        chart.asFilter = false;
                    }
                } else {
                    res = confirm('用作筛选器');
                    if (res) {
                        chart.asFilter = true;
                    }
                }
            } else {
                if (chart.asFilter) {
                    vm.toast('已将“' + clickValue.name + '”设为筛选器');
                    var index = $(chart._dom).parent().index();
                    var data = vm.totalData[index];
                    if (data) {
                        vm.setGlobalFilterData(data.dimensionSelected[0].FIELDNAME, clickValue.name, {
                            dataBaseSelected: data.dataBaseSelected,
                            tableTypeSelected: data.tableTypeSelected,
                            tableDataSelected: data.tableDataSelected
                        }, index);
                    }
                }
            }
        }
    });
}

// 6 雷达图
// function showRadar(xdata, yvalue, chart, showway, that) {
function showRadar(chartData, chart) {
    var responseData = chartData.responseData;
    // 1-1/n
    if (responseData.dimensionName.length != 1) {
        console.log('此数据无法使用雷达图表示');
        return false;
    }

    var legendData = responseData.measureName;
    var seriesData = responseData.measure.map(function(item, index) {
        return {
            value: item,
            name: responseData.measureName[index]
        };
    });
    
    var arr = [];
    responseData.measure.forEach(function(item, index) {
        arr = arr.concat(item);
    });
    var max = Math.max.apply(null, arr);
    var indicator = responseData.dimension[0].map(function(item, index) {
        return {
            name: item,
            max: max,
            // max: Math.max.apply(null, responseData.measure.map(function(item2, index2) {
            //     return item2[index];
            // })) * (Math.random().toFixed(2) * 1 + 1)
        };
    });

    var option = {
        tooltip: {
            confine: true,
        },
        
        legend: {
            // top: 50,
            top: 'middle',
            bottom: 20,
            left: 20,
            orient: 'vertical',
            data: legendData,
            type: 'scroll',
        },

        radar: {
            // shape: 'circle',
            name: {
                textStyle: {
                    borderRadius: 3,
                    padding: [3, 5]
                }
            },
            indicator: indicator,
            center: ['60%', '55%'],
            // 圆中心坐标，数组的第一项是横坐标，第二项是纵坐标。[ default: ['50%', '50%'] ]
            radius: '70%',
            // 圆的半径，数组的第一项是内半径，第二项是外半径。
            nameGap:5
        },
        series: [{
            type: 'radar',
            data: seriesData,
            top: 80,
            bottom: 50,
            label: {
                // show: true
            },
        }],
    };

    Object.assign(option, new PublicOption(chart.title));
    option.dataZoom = null;
    chart.setOption(option);

    window.addEventListener("resize", function() {
        chart.resize();
    });

    return;
    var newData = [];
    var maxValue = 0.0;
    var minValue = 0.0;
    var serisedata = [];
    if (showway == "1对1") {
        for (var i = 0; i < yvalue.length; i++) {
            if (maxValue < parseFloat(yvalue[i]))
                maxValue = parseFloat(yvalue[i]);
        }
        for (var i = 0; i < yvalue.length; i++) {
            var obj = new Object();
            obj.name = xdata[i];
            obj.max = maxValue;
            if (i == 0) {
                obj.axisLabel = {
                    show: true
                };
            }
            // obj.max = yvalue[i] + 10000;
            newData.push(obj);

        }
        var newobj = new Object();
        newobj.value = yvalue;
        newobj.name = "统计";
        serisedata.push(newobj);
    } else if (showway == "1对n") {
        for (var i = 0; i < xdata[0].length; i++) {
            var obj = new Object();
            obj.name = xdata[0][i];
            var c = [];
            for (var j = 0; j < yvalue.length; j++) {
                c.push(yvalue[j][i]);
            }
            if (maxNumber(c) > maxValue) {
                maxValue = maxNumber(c);
            }
            // obj.max = maxNumber(c) + 10000;
            // obj.max = maxValue;
            newData.push(obj);
        }

        for (var i = 0; i < yvalue.length; i++) {
            var obj = new Object();
            //obj.name = $("#ul4")[0].children[i].innerText;
            obj.name = that.measureSelected[i].FIELDNAME;
            obj.value = yvalue[i];
            serisedata.push(obj);
        }
    }

    function maxNumber(a) { //a是数组
        var maxValue = 0.0;
        for (var i = 0; i < a.length; i++) {
            if (maxValue < parseFloat(a[i]))
                maxValue = parseFloat(a[i]);
        }
        return maxValue;
    }

    chart.setOption({
        title: {
            show: true,
            text: chart.title,
            left: 'center'
        },
        tooltip: {
            confine: true,
            show: true,
        },
        radar: {
            name: {
                textStyle: {
                    borderRadius: 3,
                    padding: [3, 5]
                }
            },
            indicator: newData
        },
        series: [{
            name: '统计',
            type: 'radar',
            data: serisedata
        }]
    });

    window.addEventListener("resize", function() {
        chart.resize();
    });
    // nowChart.push(chart)
}

// 8 极坐标图(包含折线和柱状,默认柱状图)
function showPolarCoordinates (chartData, chart, type, smooth) {
    // chartData = {
    //     "responseData": {
    //         "dimension": [
    //             [
    //                 '周一',
    //                 '周二',
    //                 '周三',
    //                 '周四',
    //                 '周五',
    //                 '周六',
    //                 '周日',
    //             ],
    //             ["语文", "数学", "英语", "物理", "化学"]
    //         ],
    //         "measure": [
    //             [1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 34, 37, 40, 43, 46, 49, 52, 55, 58, 61, 64, 67, 70, 73, 76, 79, 82, 85, 88, 91, 94, 97, 100, 103],
    //             // [2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 32, 35, 38, 41, 44, 47, 50, 53, 56, 59, 62, 65, 68, 71, 74, 77, 80, 83, 86, 89, 92, 95, 98, 101, 104],
    //             // [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60, 63, 66, 69, 72, 75, 78, 81, 84, 87, 90, 93, 96, 99, 102, 105]
    //         ],
    //         "dimensionName": ["星期", "课程"],
    //         "measureName": ["小时" /* , "分钟", "秒" */ ]
    //     }
    // };

    var responseData = chartData.responseData;
    // type = 'line';
    type = type || 'bar';
    var typeName = '极坐标图';

    // 1-1/n 2-1
    if (responseData.dimensionName.length != 1 && (responseData.dimensionName.length != 2 || responseData.measureName.length != 1)) {
        console.log('此数据无法使用' + typeName + '表示');
        return false;
    }

    var legendData;
    var xAxisData = responseData.dimension[0];
    var yAxisData = {
        type: 'value'
    };

    var series;
    if (responseData.dimensionName.length == 1) {
        legendData = responseData.measureName;
        if (responseData.measureName.length == 1) {
            yAxisData.name = responseData.measureName[0];
            series = {
                data: responseData.measure[0],
                type: type,
                name: responseData.measureName[0]
            };
            series.coordinateSystem = 'polar';
            // if (smooth) {
            //     series.smooth = true;
            // }
        } else {
            series = responseData.measureName.map(function(item, index) {
                var result = {
                    name: item,
                    type: type,
                    data: responseData.measure[index],
                };
                
                result.coordinateSystem = 'polar';
                // if (smooth) {
                //     result.smooth = true;
                // }
                return result;
            });
        }
    } else if (responseData.dimensionName.length == 2) {
        yAxisData.name = responseData.measureName[0];
        series = responseData.dimension[1].map(function(item, index) {
            var result = {
                type: type,
                data: [],
            };
            
            result.coordinateSystem = 'polar';
            // if (smooth) {
            //     result.smooth = true;
            // }
            responseData.dimension[0].map(function(item2, index2) {
                result.name = item;
                var measureIndex = index2 * responseData.dimension[1].length + index;
                result.data.push(responseData.measure[0][measureIndex]);
            });
            return result;
        });
    }

    var option = {
        tooltip: {
            confine: true,
            trigger: 'axis',
        },
        // grid: {
        //     left: '15px',
        //     right: 70,
        //     top: 60,
        //     bottom: '40px',
        //     containLabel: true
        // },
        // legend: {
        //     data: legendData,
        //     top: '30',
        //     padding: [
        //         0, // 上
        //         100, // 右
        //         0, // 下
        //         100, // 左
        //     ],
        //     type: 'scroll',
        // },
        legend: {
            // top: 50,
            top: 'middle',
            bottom: 20,
            left: 20,
            orient: 'vertical',
            data: legendData,
            type: 'scroll',
        },
        // xAxis: {
        //     type: 'category',
        //     data: xAxisData,
        //     name: responseData.dimensionName[0],
        //     nameLocation: 'end'
        // },
        // yAxis: yAxisData,
        series: series,
        angleAxis: {
            type: 'category',
            data: xAxisData
        },
        radiusAxis: {},
        polar: {
            center: ['60%', '55%'],
                // 圆中心坐标，数组的第一项是横坐标，第二项是纵坐标。[ default: ['50%', '50%'] ]
            radius: '70%',
            // 圆的半径，数组的第一项是内半径，第二项是外半径。
            nameGap: 5
        },
    };

    Object.assign(option, new PublicOption(chart.title));
    option.dataZoom = null;
    chart.setOption(option);
    console.log(option);

    window.addEventListener("resize", function() {
        chart.resize();
    });

    return;

    var clickValue;
    var newxdata = [];
    var newydata = [];
    if (showway == "1对n") {
        for (var i = 0; i < yvalue.length; i++) {
            var obj = new Object();
            //obj.name = '面积';
            obj.type = 'bar';
            obj.coordinateSystem = 'polar';
            obj.data = yvalue[i];
            newydata.push(obj);
        }
        for (var i = 0; i < xdata[0].length; i++) {
            newxdata.push(xdata[0][i]);
        }
    } else if (showway == "1对1") {
        var obj = new Object();
        obj.type = 'bar';
        obj.coordinateSystem = 'polar';
        obj.data = yvalue;

        newydata.push(obj);
        for (var i = 0; i < xdata.length; i++) {
            newxdata.push(xdata[i]);
        }
    } else if (showway == "2对1") {
        for (var i = 0; i < xdata[0].length; i++) {
            if (newxdata.length == 0)
                newxdata.push(xdata[0][i]);
            if (xdata[0][i] != newxdata[newxdata.length - 1])
                newxdata.push(xdata[0][i]); //newxdata放横坐标
        }
        var aNewArr = []; //定义一个临时数组
        for (var i = 0; i < xdata[1].length; i++) { //循环遍历当前数组
            if (aNewArr.indexOf(xdata[1][i]) == -1) {
                aNewArr.push(xdata[1][i]);
            }
        }
        var aNewArr2 = [];
        for (var i = 0; i < aNewArr.length; i++) {
            // var arr = [];
            var arr = new Array(newxdata.length);
            aNewArr2.push(arr);
        }
        // for (var i = 0; i < xdata[1].length; i++) {
        //     for (var j = 0; j < aNewArr.length; j++) {
        //         if (xdata[1][i] == aNewArr[j]) {
        //             aNewArr2[j].push(yvalue[0][i]);
        //         }
        //     }
        // }

        // aNewArr 城镇村属性码
        // newxdata 地类名称
        // 遍历每一条数据(例如:城镇村属性码)
        for (var i = 0; i < xdata[1].length; i++) {
            // 当前已选维度
            // 城镇村属性码
            var m = aNewArr.indexOf(xdata[1][i]);
            // 地类名称
            var n = newxdata.indexOf(xdata[0][i]);
            aNewArr2[m][n] = yvalue[0][i];
        }
        for (var i = 0; i < aNewArr2.length; i++) {
            var obj = new Object();
            obj.name = aNewArr[i];
            obj.type = "bar";
            obj.data = aNewArr2[i];
            obj.coordinateSystem = 'polar';
            newydata.push(obj);
        }
    }
    newxdata = newxdata.map(function(item, index) {
        return {
            value: item,
            textStyle: {
                // color: '#fff'
            }
        };
    });
    chart.setOption({
        title: {
            show: true,
            text: chart.title,
            left: 'center'
        },
        // color: globalColor,
        tooltip: {
            confine: true,
            show: true,
            // trigger: 'axis',
            axisPointer: {
                type: 'shadow'
            },
            textStyle: {
                // color: 'white',
            }
        },
        // backgroundColor: '#2d3041',
        // backgroundColor: '',
        angleAxis: {
            type: 'category',
            data: newxdata,
            z: 10,
            nameTextStyle: {
                // color: '#fff'
            },
            axisLine: {
                lineStyle: {
                    // color: '#aaa'
                }
            },
        },
        radiusAxis: {
            axisLine: {
                lineStyle: {
                    // color: '#aaa'
                }
            },
            show: true,
        },
        polar: {
            textStyle: {
                // color: 'white',
            }
        },
        series: newydata,
        toolbox: {
            show: true,
            right: '20px',
            top: '10px',
            feature: {
                dataView: {
                    show: false
                },
                saveAsImage: {
                    show: true,
                    name: '图',
                    excludeComponents: ['toolbox'],
                    pixelRatio: 2,
                    // backgroundColor: '#2d3041'
                }
            },
            iconStyle: {
                normal: {
                    // color: 'white', //设置颜色
                }
            }
        },

        legend: {
            show: true,
            data: newxdata
        },

        // formatter: function (val) {
        //     clickValue = val[0];
        //     var html = '';
        //     val.forEach(function (item, index) {
        //         var name = item.name;
        //         var color = item.color;
        //         var seriesName = item.seriesName;
        //         var value = item.value || '';
        //         if (index == 0) {
        //             html += name;
        //         }
        //         html += `<br><span style="display:inline-block;margin-right:5px;border-radius:10px;width:9px;height:9px;background-color:` + color + `;"></span>` + seriesName + `: ` + value;
        //     });
        //     return html;
        // }
    });

    window.addEventListener("resize", function() {
        chart.resize();
    });
}

// 9 漏斗图(有下钻)
function showFunnel(chartData, chart) {
    // chartData = {
    //     "requestData": { "dimensionSelected": [{ "COLUMN_NAME": "行政区名称", "FIELDNAME": "行政区名称" }], "measureSelected": [{ "COLUMN_NAME": "常驻人口", "FIELDNAME": "常驻人口" }], "dataBaseSelected": "主中心测试库", "tableTypeSelected": "0", "tableDataSelected": "人口", "filterdata": "", "aggregate": "sum" }, "responseData": {
    //         "dimension": [
    //             ["五台县", "五寨县", "代县", "保德县", "偏关县", "原平市", "宁武县", "定襄县", "岢岚县", "忻府区", "河曲县", "神池县", "繁峙县", "静乐县"]
    //         ], "measure": [
    //             [307190, 111381, 221010, 165875, 115868, 506949, 166083, 225356, 87056, 567072, 149938, 109235, 277056, 161922]
    //         ], "dimensionName": ["行政区名称"], "measureName": ["常驻人口"]
    //     }
    // };

    var responseData = chartData.responseData;
    // 1-1
    if (responseData.dimensionName.length != 1 || responseData.measureName.length != 1) {
        console.log('此数据无法使用漏斗图表示');
        return false;
    }

    var seriesData = responseData.dimension[0].map(function(item, index) {
        return {
            value: responseData.measure[0][index],
            name: item
        };
    });
    var seriesMin = Math.min.apply(null, responseData.measure[0]);
    var seriesMax = Math.max.apply(null, responseData.measure[0]);
    var legendData = responseData.dimension[0];

    var option = {
        tooltip: {
            confine: true,
            trigger: 'item',
            formatter: '{b} : {c} ({d}%)'
        },
        legend: {
            top: '40',
            data: legendData,
            padding: [
                0, // 上
                100, // 右
                0, // 下
                100, // 左
            ],
            type: 'scroll',
        },
        series: [{
            name: '漏斗图',
            type: 'funnel',
            left: '10%',
            top: 70,
            bottom: 20,
            width: '80%',
            minSize: '0%',
            maxSize: '100%',
            sort: 'descending',
            // gap: 2,
            label: {
                show: true,
                position: 'right'
            },
            emphasis: {
                label: {
                    fontSize: 20
                }
            },
            data: seriesData,
            min: seriesMin,
            max: seriesMax
        }]
    };

    Object.assign(option, new PublicOption(chart.title));
    option.dataZoom = null;
    chart.setOption(option);
    window.addEventListener("resize", function() {
        chart.resize();
    });

    return;
    chart.asFilter = false;
    chart.off('click');
    chart.on('mousedown', function(params) {
        if (!$(chart._dom).hasClass('echartContent')) {
            return;
        }
        const pointInPixel = [params.offsetX, params.offsetY];
        // if (chart.containPixel('grid', pointInPixel)) {
        // var xIndex = chart.convertFromPixel({
        //     seriesIndex: 0
        // }, [params.offsetX, params.offsetY])[0];
        vm.stopPropagation = true;
        if (params.event.which == 3) {
            var res;
            if (chart.asFilter) {
                res = confirm('取消筛选器');
                if (res) {
                    chart.asFilter = false;
                }
            } else {
                res = confirm('用作筛选器');
                if (res) {
                    chart.asFilter = true;
                }
            }
        } else {
            if (chart.asFilter) {
                vm.toast('已将“' + params.name + '”设为筛选器');
                var index = $(chart._dom).parent().index();
                var data = vm.totalData[index];
                if (data) {
                    vm.setGlobalFilterData(data.dimensionSelected[0].FIELDNAME, params.name, {
                        dataBaseSelected: data.dataBaseSelected,
                        tableTypeSelected: data.tableTypeSelected,
                        tableDataSelected: data.tableDataSelected
                    }, index);
                }
            }
        }
        // }
    });
    chart.on('legendselectchanged', function() {
        vm.stopPropagation = true;
    });
    chart.on('legendscroll', function() {
        vm.stopPropagation = true;
    });
}

// 10 桑基图
function showSankey(chartData, chart) {
    //chartData = { "responseData": { "dimension": [["45871", "57304", "58430", "60048", "78253", "85989", "87721", "88988", "114324", "114714", "144612", "159163", "260582", "284853"], ["87056", "109235", "111381", "115868", "149938", "161922", "165875", "166083", "221010", "225356", "277056", "307190", "506949", "567072"]], "measure": [["43961", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "47286", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "55122", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "57008", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "77638", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "70270", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "74641", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "85186", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "98648", "", "", "", "", "", "", "", "", "", "", "", "", "102699", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "129910", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "126192", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "276726", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "370963"]], "dimensionName": ["常驻男性人口", "常驻人口"], "measureName": ["城市人口"] } };
    var responseData = chartData.responseData;
    // 2-1
    if (responseData.dimensionName.length != 2 || responseData.measureName.length != 1) {
        console.log('此数据无法使用桑基图表示');
        return false;
    }

    var links = [];
    responseData.dimension[0].map(function(item, index) {
        responseData.dimension[1].map(function(item2, index2) {
            links.push({
                source: item,
                target: item2
            });
        });
    });
    var linksNew = [];
    links.forEach(function(item, index) {
        if (responseData.measure[0][index] != null) {
            linksNew.push(Object.assign(item, {
                value: responseData.measure[0][index]
            }));
        }
    });
    links = linksNew;
    var data = [];
    responseData.dimension.map(function(item) {
        item.map(function(ite) {
            data.push({
                name: ite,
            });
        });
    });
    data = data.map(function(item, index) {
        var newIndex;
        if (index == 0) {
            newIndex = 0;
        } else {
            newIndex = index % chart._theme.color.length;
        }
        return {
            name: item.name,
            itemStyle: {
                color: chart._theme.color[newIndex]
            },
            label: {
                normal: {
                    show: true
                }
            },
            symbolSize: 0.1,
        };
    });
    var option = {
        tooltip: {
            confine: true,
            show: true,
        },
        series: [{
            type: 'sankey',
            layout: 'none',
            // focusNodeAdjacency: 'allEdges',
            data: data,
            links: links,
            label: {
                textStyle: {
                    color: chart._theme.textStyle ? chart._theme.textStyle.color : 'white'
                }
            },
            lineStyle: {
                curveness: 0.5,
                color: 'source',
                opacity: 0.5
            },
            draggable: false,
            top: 40,
            bottom: 20,
            left: 20,
            right: 100
        }],
    };

    Object.assign(option, new PublicOption(chart.title));
    option.dataZoom = null;
    chart.setOption(option);
    window.addEventListener("resize", function() {
        chart.resize();
    });
}

// 11 散点图(有下钻)
function showScatter(chartData, chart) {
    //chartData = {
    //     "requestData": { "dimensionSelected": [{ "COLUMN_NAME": "常驻男性人口", "FIELDNAME": "常驻男性人口" }, { "COLUMN_NAME": "行政区名称", "FIELDNAME": "行政区名称" }], "measureSelected": [{ "COLUMN_NAME": "常驻女性人口", "FIELDNAME": "常驻女性人口" }, { "COLUMN_NAME": "常驻人口", "FIELDNAME": "常驻人口" }, { "COLUMN_NAME": "城市人口", "FIELDNAME": "城市人口" }, { "COLUMN_NAME": "乡村人口", "FIELDNAME": "乡村人口" }, { "COLUMN_NAME": "总户数", "FIELDNAME": "总户数" }], "dataBaseSelected": "主中心测试库", "tableTypeSelected": "0", "tableDataSelected": "人口", "filterdata": "", "aggregate": "sum" },

    //     "responseData": {
    //         "dimension": [
    //             [
    //                 '周一',
    //                 '周二',
    //                 '周三',
    //                 '周四',
    //                 '周五',
    //                 '周六',
    //                 '周日',
    //             ],
    //             ["语文", "数学", "英语", "物理", "化学"]
    //         ],
    //         "measure": [
    //             [1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 34, 37, 40, 43, 46, 49, 52, 55, 58, 61, 64, 67, 70, 73, 76, 79, 82, 85, 88, 91, 94, 97, 100, 103],
    //             [2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 32, 35, 38, 41, 44, 47, 50, 53, 56, 59, 62, 65, 68, 71, 74, 77, 80, 83, 86, 89, 92, 95, 98, 101, 104],
    //             [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60, 63, 66, 69, 72, 75, 78, 81, 84, 87, 90, 93, 96, 99, 102, 105]
    //         ],
    //         "dimensionName": ["星期", "课程"],
    //         "measureName": ["小时", "分钟", "秒"]
    //     }
    // }

    //chartData = {"requestData":{"dimensionSelected":[{"COLUMN_NAME":"常驻男性人口","FIELDNAME":"常驻男性人口"},{"COLUMN_NAME":"行政区名称","FIELDNAME":"行政区名称"}],"measureSelected":[{"COLUMN_NAME":"常驻人口","FIELDNAME":"常驻人口"},{"COLUMN_NAME":"城市人口","FIELDNAME":"城市人口"},{"COLUMN_NAME":"乡村人口","FIELDNAME":"乡村人口"},{"COLUMN_NAME":"常驻女性人口","FIELDNAME":"常驻女性人口"},{"COLUMN_NAME":"总户数","FIELDNAME":"总户数"}],"dataBaseSelected":"主中心测试库","tableTypeSelected":"0","tableDataSelected":"人口","filterdata":"","aggregate":"sum"},"responseData":{"dimension":[["45871","57304","58430","60048","78253","85989","87721","88988","114324","114714","144612","159163","260582","284853"],["五台县","五寨县","代县","保德县","偏关县","原平市","宁武县","定襄县","岢岚县","忻府区","河曲县","神池县","繁峙县","静乐县"]],"measure":[[0,0,0,0,0,0,0,0,87056,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,109235,0,0,0,111381,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115868,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,149938,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,161922,0,0,0,165875,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,166083,0,0,0,0,0,0,0,0,0,0,0,0,0,0,225356,0,0,0,0,0,0,0,0,221010,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,277056,0,307190,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,506949,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,567072,0,0,0,0],[0,0,0,0,0,0,0,0,43961,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,47286,0,0,0,55122,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,57008,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,77638,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,70270,0,0,0,74641,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,85186,0,0,0,0,0,0,0,0,0,0,0,0,0,0,98648,0,0,0,0,0,0,0,0,102699,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,129910,0,126192,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,276726,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,370963,0,0,0,0],[0,0,0,0,0,0,0,0,43095,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,61949,0,0,0,56259,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,58860,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,72300,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,91652,0,0,0,91234,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,80897,0,0,0,0,0,0,0,0,0,0,0,0,0,0,126708,0,0,0,0,0,0,0,0,118311,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,147146,0,180998,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,230223,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,196109,0,0,0,0],[0,0,0,0,0,0,0,0,41185,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,51931,0,0,0,52951,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,55820,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,71685,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,75933,0,0,0,78154,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,77095,0,0,0,0,0,0,0,0,0,0,0,0,0,0,111032,0,0,0,0,0,0,0,0,106296,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,132444,0,148027,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,246367,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,282219,0,0,0,0],[0,0,0,0,0,0,0,0,38276,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,45819,0,0,0,52309,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,46144,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64735,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,60285,0,0,0,65106,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,68679,0,0,0,0,0,0,0,0,0,0,0,0,0,0,102158,0,0,0,0,0,0,0,0,94212,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,116624,0,139831,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,198019,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,232363,0,0,0,0]],"dimensionName":["常驻男性人口","行政区名称"],"measureName":["常驻人口","城市人口","乡村人口","常驻女性人口","总户数"]}}

    var responseData = chartData.responseData;
    // 1/2-1/n
    if (responseData.dimensionName.length > 2) {
        console.log('此数据无法使用散点图表示');
        return false;
    }

    var seriesArr = responseData.dimension[0].map(function(item, index) {
        return [item];
    });

    if (responseData.dimensionName.length > 1) {
        responseData.dimension.forEach(function(item, index) {
            if (index == 0) {
                return;
            }
            var arr = [];
            seriesArr.forEach(function(item2, index2) {
                item.forEach(function(item3, index3) {
                    arr.push((item2.toString() + ',' + item3).split(','));
                });
            });
            seriesArr = arr;
        });
    }
    // console.log(seriesArr);

    seriesArr.map(function(item, index) {
        responseData.measure.forEach(function(item2, index2) {
            item.push(item2[index]);
        });
        return item;
    });
    // console.log(seriesArr);

    // 处理为所需数据
    var seriesData = [];
    var itemStyle = {
        opacity: 0.8,
        shadowBlur: 10,
        shadowOffsetX: 0,
        shadowOffsetY: 0,
        shadowColor: 'rgba(0, 0, 0, 0.5)'
    };
    if (responseData.dimensionName.length > 1) {
        var demension2Length = responseData.dimension[1].length;
        seriesData = new Array(demension2Length);

        seriesArr.forEach(function(item, index) {
            var remainder = index % demension2Length;
            var name = item[1];
            item.splice(1, 1);
            if (seriesData[remainder]) {
                seriesData[remainder].data.push(item);
            } else {
                seriesData[remainder] = {
                    name: name,
                    type: 'scatter',
                    itemStyle: itemStyle,
                    data: [item]
                };
            }
        });
    } else {
        // 一维
        seriesData = [{
            name: responseData.measureName[0],
            type: 'scatter',
            itemStyle: itemStyle,
            data: seriesArr
        }];
    }
    var schema = responseData.measureName.map(function(item, index) {
        return {
            name: item,
            index: index,
            text: item
        };
    });
    var legendData = responseData.dimension[1];
    var visualMpaDataItem = {
        left: 'right',
        itemHeight: 70,
        calculable: true,
        precision: 0.1,
        controller: {
            inRange: {
                color: [chart._theme.color[0]]
            },
            outOfRange: {
                color: ['#444']
            }
        },
        textStyle: {
            color: chart._theme.textStyle.color
        },
        textGap: 15
    };

    var visualMpaData = [];
    var max, min;
    if (responseData.measureName[1]) {
        max = Math.max.apply(null, responseData.measure[1]);
        min = Math.min.apply(null, responseData.measure[1]);
        var item1 = {
            top: '50',
            dimension: 2,
            min: min - 10,
            max: max + 10,
            text: ['大小：' + responseData.measureName[1]],
            inRange: {
                symbolSize: [10, 70]
            },
            outOfRange: {
                symbolSize: [10, 70],
                color: ['rgba(255,255,255,.2)']
            },
        };
        visualMpaData.push(Object.assign({}, visualMpaDataItem, item1));
    }

    if (responseData.measureName[2]) {
        max = Math.max.apply(null, responseData.measure[1]);
        min = Math.min.apply(null, responseData.measure[1]);
        var item2 = {
            // bottom: '50',
            top: '180',
            dimension: 3,
            min: min - 10,
            max: max + 10,
            text: ['明暗：' + responseData.measureName[2]],
            inRange: {
                colorLightness: [1, 0.5]
            },
            outOfRange: {
                color: ['rgba(255,255,255,.2)']
            },
        };
        visualMpaData.push(Object.assign({}, visualMpaDataItem, item2));
    }

    var option = {
        legend: {
            top: '40',
            data: legendData,
            padding: [
                0, // 上
                100, // 右
                0, // 下
                100, // 左
            ],
            type: 'scroll',
        },
        grid: {
            left: 15,
            right: 140,
            top: '80',
            bottom: 40,
            containLabel: true
        },
        tooltip: {
            confine: true,
            formatter: function(obj) {
                var value = obj.value;
                var html = '<div style="border-bottom: 1px solid rgba(255,255,255,.3);padding-bottom: 7px;margin-bottom: 7px;">';
                html += responseData.dimensionName[0] + '：' + obj.name;
                if (responseData.dimensionName[1]) {
                    html += '<br/>' + responseData.dimensionName[1] + '：' + obj.seriesName;
                }
                html += '</div>';
                schema.forEach(function(item, index) {
                    html += item.text + '：' + value[index + 1] + '<br>';
                });
                return html;
            }
        },
        xAxis: {
            type: 'category',
            name: responseData.dimensionName[0],
        },
        yAxis: {
            type: 'value',
            name: responseData.measureName[0],
        },
        visualMap: visualMpaData,
        series: seriesData
    };

    if (visualMpaData.length == 0) {
        option.grid.right = 80;
    }

    Object.assign(option, new PublicOption(chart.title));
    chart.setOption(option);

    window.addEventListener("resize", function() {
        chart.resize();
    });
}

// 12 弦图
function showChordal(chartData, chart) {
    //chartData = { "responseData": { "dimension": [["45871", "57304", "58430", "60048", "78253", "85989", "87721", "88988", "114324", "114714", "144612", "159163", "260582", "284853"], ["87056", "109235", "111381", "115868", "149938", "161922", "165875", "166083", "221010", "225356", "277056", "307190", "506949", "567072"]], "measure": [["43961", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "47286", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "55122", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "57008", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "77638", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "70270", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "74641", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "85186", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "98648", "", "", "", "", "", "", "", "", "", "", "", "", "102699", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "129910", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "126192", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "276726", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "370963"]], "dimensionName": ["常驻男性人口", "常驻人口"], "measureName": ["城市人口"] } };
    var responseData = chartData.responseData;
    // 2-1
    if (responseData.dimensionName.length != 2 || responseData.measureName.length != 1) {
        console.log('此数据无法使用弦图表示');
        return false;
    }

    var links = [];
    responseData.dimension[0].map(function(item, index) {
        responseData.dimension[1].map(function(item2, index2) {
            links.push({
                source: item,
                target: item2
            });
        });
    });

    var maxValue = Math.max.apply(null, responseData.measure[0]);
    var times = Math.floor(maxValue / 50 * 100) / 100;
    links = links.map(function(item, index) {
        return Object.assign(item, {
            value: responseData.measure[0][index],
            lineStyle: {
                normal: {
                    width: (responseData.measure[0][index] / times).toFixed(2),
                    opacity: 0.5
                }
            }
        });
    });

    var data = [];
    responseData.dimension.map(function(item) {
        item.map(function(ite) {
            data.push({
                name: ite,
            });
        });
    });
    data = data.map(function(item, index) {
        var newIndex;
        if (index == 0) {
            newIndex = 0;
        } else {
            newIndex = index % chart._theme.color.length;
        }
        return {
            name: item.name,
            itemStyle: {
                color: chart._theme.color[newIndex]
            },
            label: {
                normal: {
                    show: true
                }
            },
            symbolSize: 0.1,
        };
    });

    var option = {
        tooltip: {
            confine: true,
            show: true,
        },
        series: [{
            radius: '50%',
            type: 'graph',
            layout: 'circular',
            circular: {
                rotateLabel: true
            },
            data: data,
            links: links,
            label: {
                position: 'right',
                formatter: '{b}',
            },
            lineStyle: {
                color: 'source',
                curveness: 0.3
            },
            top: 80,
            bottom: 50,
        }]
    };

    Object.assign(option, new PublicOption(chart.title));
    option.dataZoom = null;
    chart.setOption(option);

    window.addEventListener("resize", function() {
        chart.resize();
    });
}

// 13 复合图
function showUnion(chartData, chart) {
    // chartData = {
    //     "requestData": {
    //         "dimensionSelected": [{ "COLUMN_NAME": "行政区名称", "FIELDNAME": "行政区名称" }],
    //         "measureSelected": [
    //             { "COLUMN_NAME": "总户数", "FIELDNAME": "总户数" },
    //             { "COLUMN_NAME": "常驻男性人口", "FIELDNAME": "常驻男性人口" },
    //             { "COLUMN_NAME": "常驻女性人口", "FIELDNAME": "常驻女性人口" },
    //             { "COLUMN_NAME": "城市人口", "FIELDNAME": "城市人口" },
    //             { "COLUMN_NAME": "乡村人口", "FIELDNAME": "乡村人口" },
    //             { "COLUMN_NAME": "常驻人口", "FIELDNAME": "常驻人口" }
    //         ],
    //         "dataBaseSelected": "主中心测试库",
    //         "tableTypeSelected": "0",
    //         "tableDataSelected": "人口",
    //         "filterdata": "",
    //         "aggregate": "sum"
    //     },
    //     "responseData": {
    //         "dimension": [
    //             ["五台县", "五寨县", "代县", "保德县", "偏关县", "原平市", "宁武县", "定襄县", "岢岚县", "忻府区", "河曲县", "神池县", "繁峙县", "静乐县"]
    //         ],
    //         "measure": [
    //             ["139831", "52309", "94212", "65106", "46144", "198019", "68679", "102158", "38276", "232363", "64735", "45819", "116624", "60285"],
    //             ["159163", "58430", "114714", "87721", "60048", "260582", "88988", "114324", "45871", "284853", "78253", "57304", "144612", "85989"],
    //             ["148027", "52951", "106296", "78154", "55820", "246367", "77095", "111032", "41185", "282219", "71685", "51931", "132444", "75933"],
    //             ["126192", "55122", "102699", "74641", "57008", "276726", "85186", "98648", "43961", "370963", "77638", "47286", "129910", "70270"],
    //             ["180998", "56259", "118311", "91234", "58860", "230223", "80897", "126708", "43095", "196109", "72300", "61949", "147146", "91652"],
    //             ["307190", "111381", "221010", "165875", "115868", "506949", "166083", "225356", "87056", "567072", "149938", "109235", "277056", "161922"]
    //         ],
    //         "dimensionName": ["行政区名称"],
    //         "measureName": ["总户数", "常驻男性人口", "常驻女性人口", "城市人口", "乡村人口", "常驻人口"]
    //     }
    // }

    var responseData = chartData.responseData;

    // 1-1/n
    if (responseData.dimensionName.length != 1) {
        console.log('此数据无法使用复合图表示');
        return false;
    }

    var typeArr = ['line', 'bar', 'scatter'];
    var series = responseData.measureName.map(function(item, index) {
        var type;
        if (index < typeArr.length) {
            type = typeArr[index];
        } else {
            type = typeArr[index % typeArr.length];
        }
        return {
            name: item,
            type: type,
            data: responseData.measure[index]
        };
    });
    var option = {
        tooltip: {
            confine: true,
            show: true,
        },
        grid: {
            left: '15px',
            right: '60px',
            bottom: '40px',
            top: '80px',
            containLabel: true
        },
        legend: {
            data: responseData.measureName,
            top: '40',
            padding: [
                0, // 上
                100, // 右
                0, // 下
                100, // 左
            ],
            type: 'scroll',
        },
        xAxis: {
            type: 'category',
            data: responseData.dimension[0],
            name: responseData.dimensionName[0],
            nameLocation: 'end',
        },
        yAxis: {
            type: 'value'
        },
        series: series
    };

    Object.assign(option, new PublicOption(chart.title));
    chart.setOption(option);

    window.addEventListener("resize", function() {
        chart.resize();
    });
}

// 14 旭日图(矩形树图)n-n

// 15 平行坐标系

// 16 主题河流图